<template>
	<view class="page-box">
		<view class="bg-top">
			<image src="https://huodtg.oss-cn-hangzhou.aliyuncs.com/hd/miniprogram/image-bg.png" mode="widthFix" class="image-bg"></image>
			<view class="bg-inner">
				<uni-nav-bar ref="navBar" statusBar title="火动策划人" :border="false" backgroundColor="transparent"
					@clickLeft="goBack">
					<template v-slot:left>
						<image class="size-32" src="@/static/svg/icon-back.svg" />
					</template>
				</uni-nav-bar>
				<view class="img-box">
					<view class="flex flex-col" style="margin-left: 10px;">
						<image src="https://huodtg.oss-cn-hangzhou.aliyuncs.com/hd/miniprogram/image-title.png" mode="widthFix" class="image-title"></image>
						<image src="@/applyPages/static/image/image-tip.png" mode="widthFix" class="image-tip"></image>
					</view>
					<view>
						<image src="https://huodtg.oss-cn-hangzhou.aliyuncs.com/hd/miniprogram/img-right.png" mode="widthFix" class="img-right"></image>
					</view>
				</view>
			</view>


		</view>
		<view class="join-inner-box">
			<view class="join-header">入驻权益</view>
			<view class="join-inner">
				<view class="join-item">
					<view class="flex item-center">
						<image src="@/applyPages/static/apply-2.svg" mode="widthFix" class="apply-image"></image>
						<text class="apply-title">0 元入驻，0 佣金</text>
					</view>
					<view class="apply-tip">0 元入驻，0 佣金</view>
				</view>
				<view class="join-item">
					<view class="flex item-center">
						<image src="@/applyPages/static/apply-1.svg" mode="widthFix" class="apply-image"></image>
						<text class="apply-title">一键发布</text>
					</view>
					<view class="apply-tip">入驻后可快速发布活动</view>
				</view>
				<view class="join-item">
					<view class="flex item-center">
						<image src="@/applyPages/static/apply-3.svg" mode="widthFix" class="apply-image"></image>
						<text class="apply-title">分销赋能</text>
					</view>
					<view class="apply-tip">一键开启分销，流量裂变</view>
				</view>
				<view class="join-item">
					<view class="flex item-center">
						<image src="@/applyPages/static/apply-4.svg" mode="widthFix" class="apply-image"></image>
						<text class="apply-title">空中分账</text>
					</view>
					<view class="apply-tip">多角色灵活分账，快速结算</view>
				</view>
			</view>
		</view>
		<view class="fix-btn" @click="joinClass" v-if="show">立即加入</view>
		<view class="k-page"></view>
	</view>
</template>

<script setup>
	import {ref} from 'vue'
	import {onLoad} from '@dcloudio/uni-app'
	import { myPageApi } from '@/api/index.js'
	import { validSettleCode } from '@/api/business.js'
	import {
		useUserStore
	} from '@/stores/modules/user.js'
	import { parseScene } from '@/utils/index.js'
	const userStore = useUserStore()
	const goBack = () => {
		if(getCurrentPages().length === 1) {
			uni.reLaunch({
				url: '/pages/home/home?tab=4'
			})
			return
		}
		uni.navigateBack()
	}
	const code = ref('')
	const show = ref(true)
	const joinClass = () => {
		if(userStore.userInfo && userStore.userInfo.openid){
			let params = code.value?`?code=${code.value}`:``
			// uni.redirectTo({
			// 	url: `/applyPages/bussinessApply/bussinessAgreement${params}`
			// })
			userStore.setApplyType('1')
			uni.navigateTo({
				// url: `/applyPages/bussinessApply/bussinessApplyType${params}`
				url: `/applyPages/bussinessApply/bussinessAgreement${params}`
			})
		}else{
			let params = code.value?`?code=${code.value}&re=busi`:``
			uni.reLaunch({
				url: `/pagesA/login/login${params}`
			})
		}
	}
	const queryList = () => {
		// if (userStore.isAgent || userStore.isMerchant) {
		myPageApi().then(res => {
			if(res.auditState == 2){
				uni.showToast({
					icon: 'none',
					title: '已是商家',
					complete() {
						
					}
				})
				setTimeout(() => {
					uni.reLaunch({
						url:"/pages/home/home?tab=4"
					})
				},1000)
				// 已是商家
			}else if(res.auditState == 1||res.auditState == 3||res.auditState == 4){
				uni.showToast({
					icon: 'none',
					title: '你已提交申请',
					complete() {
						
					}
				})
				setTimeout(() => {
					uni.reLaunch({
						url:"/applyPages/bussinessApply/applyResult/applyResult"
					})
				},1000)
			}else{
				getValidSettleCode()
			}
		})
		// } else {
		// 	paging.value.complete()
		// }
	}
	const getValidSettleCode = async () => {
		if(code.value){
			validSettleCode({settleCode:code.value}).then(result => {
				
			}).catch(err => {
				if(err.code == 10012){//链接失效
					// emit('nextStep',{step:5})
					// setTimeout(()=> {
					// 	uni.reLaunch({
					// 		url:'/applyPages/inviteApply/loseLink'
					// 	})
					// },1000)
					show.value = false
				}
			})
			
		}
		
	}
	onLoad((query) => {
		queryList()
		if(query.code){
			code.value = query.code
		}
		// 扫码打开
		if (query.scene) {
			const scene = parseScene(query.scene)
			if (!query.code && scene.code) {
				code.value = scene.code
			}
		}
		// getValidSettleCode()
	})
</script>

<style lang="scss" scoped>
.page-box{
	background: linear-gradient(180deg, #ECC68B 0%, #FD2F33 48.02%, #FA4543 100%);
	width: 100vw;
	min-height: 100vh;
}
.bg-inner{
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
}
.bg-top{
	position: relative;
	top: 0;
	left: 0;
	overflow-y: auto;
	.image-bg{
		width: 100%;
		// position: absolute;
		// left: 0;
		// top: 0;
	}
	.image-title{
		width: 316rpx;
		margin-top: 90rpx;
	}
	.image-tip{
		width: 356rpx;
		margin-top: 20px;
	}
	.img-right{
		width: 468rpx;
		position: absolute;
		left: 278rpx;
		top: 0;
	}
}
.img-box{
	margin-top: 20px;
	position: relative;
}
.join-inner-box{
	margin: 0 20px;
	.join-header{
		background: linear-gradient(90.08deg, #EEBC86 0.07%, #FA4744 99.94%);
		width: 100%;
		height: 50px;
		color: #ffffff;
		font-family: DIN Alternate;
		font-size: 20px;
		font-weight: 700;
		border-top-left-radius: 8px;
		border-top-right-radius: 8px;
		line-height: 50px;
		box-sizing: border-box;
		padding: 0 10px;
	}
	.join-inner{
		border-bottom-left-radius: 8px;
		border-bottom-right-radius: 8px;
		background-color: #ffffff;
		padding:  10px;
		.join-item{
			margin-bottom: 16px;
			&:last-child{
				margin-bottom: 0;
			}
		}
	}
}
.apply-image{
	width: 24px;
}
.apply-title{
	font-family: PingFang SC;
	font-size: 16px;
	font-weight: 600;
	line-height: 22px;
	color: rgba(250, 69, 67, 1);
	margin-left: 10px;
}
.apply-tip{
	font-family: PingFang SC;
	font-size: 12px;
	font-weight: 400;
	line-height: 17px;
	color: rgba(51, 51, 51, 1);
	margin-top: 10px;
}
.k-page{
	height: 40px;
}
.fix-btn{
	// position: fixed;
	// bottom: 0;
	// left: 0;
	width: calc(100% - 40px);
	margin: 20px;
	height: 46px;
	line-height: 46px;
	background-color: #ffffff;
	text-align: center;
	color: rgba(250, 72, 69, 1);
	font-weight: 400;
	font-size: 16px;
	border-radius: 8px;
}
</style>
